package com.zpself.module.basic.枚举.解决开闭原则;

import org.junit.Assert;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2020/8/25 23:33
 */
public class EnumTest {
    public static void main(String[] args) {
        //test_1_No();
        test_2_Yes();
    }
    private static void test_2_Yes() {
        String sign = "toutiao";
        ChannelRuleEnum channelRule = ChannelRuleEnum.match(sign);
        if(channelRule==null)
            Assert.fail("未找到处理类！");

        GeneralChannelRule rule = channelRule.channel;
        rule.process();
    }
    private static void test_1_No() {
        //这里我们模拟接收到的数据，其渠道为为TOUTIAO，来自头条的数据
        String sign = "TOUTIAO";
        GeneralChannelRule rule=null;
        //根据对应渠道获取对应的具体规则实现类
        if (ChannelRuleEnum.TENCENT.name().equals(sign)) {
            rule = new TencentChannelRule();
        } else if (ChannelRuleEnum.TOUTIAO.name().equals(sign)) {
            rule = new TouTiaoChannelRule();
        } else {
            System.out.println("未匹配到");
            //匹配不到
        }
        //执行
        rule.process();
    }
}
